package com.sunshine.lnuplus.view.Function;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProviders;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.material.snackbar.Snackbar;
import com.sunshine.lnuplus.R;
import com.sunshine.lnuplus.databinding.FragmentFunctionBinding;
import com.sunshine.lnuplus.view.Main.MainActivity;
import com.sunshine.lnuplus.view.SchoolDate.SchoolDateActivity;
import com.sunshine.lnuplus.view.WebView.WebViewActivity;

public class FunctionFragment extends Fragment implements View.OnClickListener {

    private FunctionViewModel mViewModel;
    private MainActivity activity;
    private FragmentFunctionBinding binding;

    public static FunctionFragment newInstance() {
        return new FunctionFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        activity = (MainActivity) getActivity();
        binding = DataBindingUtil.inflate(inflater,R.layout.fragment_function,container,false);
        View view = binding.getRoot();
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(FunctionViewModel.class);

        activity.getSupportActionBar().setSubtitle(null);
        binding.functionSearchScore.setOnClickListener(this);
        binding.functionSchoolDate.setOnClickListener(this);
        binding.functionBus.setOnClickListener(this);
        binding.functionCustom.setOnClickListener(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.function_search_score:
                Snackbar.make(activity.binding.mainCoordinatorLayout,"现在还不是查询成绩的时间噢~",Snackbar.LENGTH_SHORT).show();
                break;
            case R.id.function_school_date:
                startActivity(new Intent(activity, SchoolDateActivity.class));
                break;
            case R.id.function_bus:
                break;
            case R.id.function_custom:
                Bundle bundle = new Bundle();
                bundle.putString("label","肺炎实时疫情");
                bundle.putString("url","https://ncov.dxy.cn/ncovh5/view/pneumonia?scene=2&clicktime=1579582238&enterid=1579582238&from=timeline&isappinstalled=0");
                startActivity(new Intent(activity, WebViewActivity.class).putExtras(bundle));
                break;
        }
    }
}
